package com.zhang.webadmin.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class R {

    private int code;
    private String msg;
    private Object info;

    private final static int ok = 0;
    private final static int fail = 1;
    private final static int needLogin = 10;

    public static R ok() {
        return new R(ok, "", null);
    }

    public static R ok(Object data) {
        return new R(ok, "", data);
    }

    public static R fail(String msg) {
        return new R(fail, msg, null);
    }

    public static R needLogin(String msg) {
        return new R(needLogin, msg, null);
    }

    public static R page(List<?> items, long total) {
        Map<String, Object> ret = new HashMap<>();
        ret.put("items", items);
        ret.put("total", (int) total);

        return R.ok(ret);
    }
}
